from os.path import join
from django.conf import settings
from django.forms import Textarea
from django.utils.safestring import mark_safe
from django.template.loader import render_to_string

from django.utils.translation.trans_real import get_language

class WYMEditor(Textarea):
    class Media:
        js = [join(settings.MEDIA_URL, path) for path in (
            'lib/wymeditor/jquery.wymeditor.js',
        )]
        css = {
            'all': [join(settings.MEDIA_URL, path) for path in (
#                        'css/jquery/cupertino/jquery-ui.css',
                    )],
        }

    def __init__(self, attrs=None):
        default_attrs = {'class': 'wymeditor'}
        if attrs:
            default_attrs.update(attrs)
        super(WYMEditor, self).__init__(default_attrs)

    def render_textarea(self, name, value, attrs=None):
        return super(WYMEditor, self).render(name, value, attrs)

#    def render_additions(self, name, value, attrs=None):
#        language = get_language()
#        context = {
#            'name': name,
#            'language': language,
#            'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
#            'WYM_TOOLS': mark_safe(text_settings.WYM_TOOLS),
#            'WYM_CONTAINERS': mark_safe(text_settings.WYM_CONTAINERS),
#            'WYM_CLASSES': mark_safe(text_settings.WYM_CLASSES),
#            'WYM_STYLES': mark_safe(text_settings.WYM_STYLES),
#            'WYM_STYLESHEET': mark_safe(text_settings.WYM_STYLESHEET),
#            'installed_plugins': self.installed_plugins,
#        }
#        return mark_safe(render_to_string(
#            'cms/plugins/widgets/wymeditor.html', context))
#
#    def render(self, name, value, attrs=None):
#        return self.render_textarea(name, value, attrs) + \
#            self.render_additions(name, value, attrs)